//文件上传逻辑

$(".layui-icon-picture").click(function () {
    $("#file").click();

});

$("#file").on("change", function () {
    let user_name=$("input[name='user_name']").val();
    let client_id=$("input[name='client_id']").val();
    let room_id=$("input[name='room_id']").val();
    let sex=$("input[name='sex']").val();
    let address=$(".address").val();
    let file = $(this);
    $.ajax({
        url: '/upload',
        type: 'POST',
        cache: false,
        data: new FormData($('#uploadForm')[0]),
        processData: false,
        contentType: false
    }).done(function (res) {

        res = JSON.parse(res);

        if (res.code == 200) {

            layer.msg("发送成功");
            let send = {
                message: res.path,
                room_id: room_id,
                client_id: client_id,
                sex: sex,
                img: "img",
                user_name: user_name,
                address:address
            }

            $.ajax({
                type: "post",
                url: "/send",
                data: send,
                success: function (data) {

                }
            })

        } else if (res.code == 400) {
            layer.msg(res.message + "注:只能发送图片格式哦~且图片不能大于2.5MB");
        }
        file.val("");

    }).fail(function (res) {

    });
})